﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DbDoc.BusinessObjects;
using System.Collections.ObjectModel;

namespace DbDoc.PowerDoc.Model
{
    public  class DatabaseModel : DbObjectModel
    {     
       

        public DatabaseModel()  :base()
        { 
            
            Children = new ObservableCollection<DbObjectModel>();
            DbObjectModel table = new DbObjectModel() { Name = "Tables", Parent = this };
            DbObjectModel views = new DbObjectModel() { Name = "Views", Parent = this };
            DbObjectModel functions = new DbObjectModel() { Name = "Functions", Parent = this };
            DbObjectModel procs = new DbObjectModel() { Name = "Stored Procedures", Parent = this };

            Children.Add(table);
            Children.Add(views);
            Children.Add(functions);
            Children.Add(procs);
        }

        public DatabaseModel(Database db)
            : base(db)
        {
            Children = new ObservableCollection<DbObjectModel>();
            DbObjectModel table = new DbObjectModel() { Name = "Tables", Parent = this };
            DbObjectModel views = new DbObjectModel() { Name = "Views", Parent = this };
            DbObjectModel functions = new DbObjectModel() { Name = "Functions", Parent = this };
            DbObjectModel procs = new DbObjectModel() { Name = "Stored Procedures", Parent = this };

            foreach (Table t in ((Database)UnderlyingDbObject).Tables)
            {
                table.Children.Add(new DbObjectModel(t));
            }

            foreach (StoredProc sp in ((Database)UnderlyingDbObject).Procs)
            {
                procs.Children.Add(new DbObjectModel(sp));
            }
            Children.Add(table);
            Children.Add(views);
            Children.Add(functions);
            Children.Add(procs);
        }
    }
}
